package com.beiji.usercentert.exception;

import com.beiji.usercentert.commoon.BaseResponse;
import com.beiji.usercentert.commoon.ErrorCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandle {

    @ExceptionHandler(BusinessException.class)
    public BaseResponse businessException(BusinessException e){
        return BaseResponse.error(e.getErrorCode(), e.getDescription());
    }

    @ExceptionHandler(RuntimeException.class)
    public BaseResponse runtimeException(RuntimeException e){
        return BaseResponse.error(ErrorCode.SYSTEM_EXCEPTION);
    }
}
